package com.cs543.j.client.service;

import java.text.DateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import com.cs543.j.client.MobileCloudClient;
import com.cs543.j.client.TCPClient;
import com.cs543.j.client.comm.RmiServerInstance;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class LocalService extends Service {
	
	Timer m_timer;
	String m_name;

	@Override
	public void onCreate() {
		super.onCreate();
		Log.i("LocalService", "Service Created");
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.i("LocalService", "Service destroyed");
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		Log.i("LocalService", "Service started");
		
		newRMI();
		
		m_timer = new Timer();
		m_name = new String("ToDefineSomehow");
		
		m_timer.scheduleAtFixedRate(new TimerTask() {
			@Override
			public void run() {
				if(MobileCloudClient.clientName != null)
					MobileCloudClient.m_udpClient.register(MobileCloudClient.clientName);
			}
		}, new Date(), 60000);
		
		
		
		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	
	public void newRMI()
	{
		 new RmiServerInstance();
	}
	

}
